package com.iting;

import com.iting.test.filter.MyDateConvert;
import com.iting.test.properties.MyProperties;
import com.iting.test.template.MyTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.converter.Converter;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.Date;

/**
 * @author iting Nie
 * @version 1.1
 * @create 2022/1/14
 */

@SpringBootApplication
@EnableAsync
public class DemoApplication extends SpringBootServletInitializer {
	@Value("${code.tem.path:null}")
	private String temPath;

    public static void main(String[] args) {
		ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);
		DemoApplication demoApplication = (DemoApplication)context.getBean("demoApplication");
		System.out.println(demoApplication.temPath);
	}

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		return builder.sources(DemoApplication.class);
	}

	@Bean
	public MyTemplate myTemplate(MyProperties myProperties){
		System.out.println("启动类");
		return new MyTemplate(myProperties);
	}

	@Bean
	public Converter<String, Date> myDateConverter(){
    	return new MyDateConvert();
	}

	// 无参构造
	public DemoApplication() {
	}
}
